package com.appbee.defaultapp.client;

import javax.inject.Inject;
import javax.inject.Provider;

import com.appbee.article.client.ArticleActivityModul;
import com.appbee.cm.client.modular.presenter.ModulGroup;
import com.appbee.cm.client.modular.presenter.ModulGroups;
import com.appbee.cm.client.nav.presenter.NavStyleRegistry;
import com.appbee.cm.client.nav.presenter.SimpleNavActivityModul;
import com.appbee.cm.client.regionunit.presenter.StyleRegistry;
import com.appbee.cm.client.regionunit.ui.ActivityPanel;
import com.appbee.cm.client.regionunit.ui.StaticActivityPanel;
import com.appbee.core.client.layout.LayoutManager;
import com.appbee.core.client.layout.impl.SimplePageLayout;
import com.appbee.core.client.startup.StartupChain;
import com.appbee.core.client.startup.StartupLink;
import com.appbee.defaultapp.client.design.StyleResource;
import com.appbee.defaultapp.client.design.StyleResoureces;
import com.appbee.defaultapp.client.design.nav.TopNav;
import com.appbee.gdata.picasa.client.PicasaActivityModul;
import com.appbee.gdata.picasa.client.PicasaPhotoShowActivityModul;
import com.appbee.news.client.NewsActivityModul;
import com.appbee.news.client.RollingNewsActivityModul;
import com.appbee.songs.client.SongActivityModul;
import com.appbee.songs.client.SongsListActivityModul;
import com.appbee.user.client.UserInfoActivityModul;
import com.appbee.user.client.UserListActivityModul;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.SimplePanel;

public class DefaultStartupLink implements StartupLink
{
	private final Provider<ActivityPanel> activityPanelProvider;
	private final Provider<StaticActivityPanel> staticActivityPanelProvider;
	private final StyleResoureces shellResources;

	@Inject
	public DefaultStartupLink(	ModulGroups modulGroups,
							Provider<ActivityPanel> activityPanelProvider,
							Provider<StaticActivityPanel> staticActivityPanelProvider,
							UserInfoActivityModul userInfoActivityModul,
							NewsActivityModul newsActivityModul,
							RollingNewsActivityModul rollingNewsActivityModul,
							SongActivityModul songActivityModul,
							SongsListActivityModul songsListActivityModul,
							UserListActivityModul userListActivityModul,
							PicasaActivityModul picasaActivityModul,
							PicasaPhotoShowActivityModul photoShowActivityModul,
							ArticleActivityModul articleActivityModul,
							SimpleNavActivityModul simpleNavActivityModul,
							StyleResoureces shellResources,
							StyleRegistry styleRegistry,
							NavStyleRegistry navStyleRegistry,
							LayoutManager layoutManager)
	{
		this.activityPanelProvider = activityPanelProvider;
		this.staticActivityPanelProvider = staticActivityPanelProvider;
		this.shellResources = shellResources;

		// Group moduls
		ModulGroup navGroup = modulGroups.add("Navigation");
		navGroup.addModul(simpleNavActivityModul);
		ModulGroup articleGroup = modulGroups.add("Article");
		articleGroup.addModul(articleActivityModul);
		ModulGroup usersGroup = modulGroups.add("Users");
		usersGroup.addModul(userInfoActivityModul).addModul(userListActivityModul);
		ModulGroup newsGroup = modulGroups.add("News");
		newsGroup.addModul(newsActivityModul);
		newsGroup.addModul(rollingNewsActivityModul);
		ModulGroup playlistGroup = modulGroups.add("Playlist");
		playlistGroup.addModul(songsListActivityModul);
		playlistGroup.addModul(songActivityModul);
		ModulGroup picasaGroup = modulGroups.add("Picasa");
		picasaGroup.addModul(picasaActivityModul);
		picasaGroup.addModul(photoShowActivityModul);

		// Register moduls.
		userInfoActivityModul.register();
		newsActivityModul.register();
		rollingNewsActivityModul.register();
		userListActivityModul.register();
		songActivityModul.register();
		songsListActivityModul.register();
		articleActivityModul.register();
		picasaActivityModul.register();
		photoShowActivityModul.register();
		simpleNavActivityModul.register();

		// Register style
		StyleResource style = shellResources.style();
		styleRegistry
.register(style.block(), "block", "Block");
		styleRegistry.register(style.fixedSize(),
								"fixedSize",
								"Fixed size");
		styleRegistry.register(style.floatLeft(),
								"left",
								"Float left");
		styleRegistry.register(style.floatRight(),
								"right",
								"Float right");

		// Register nav style
		navStyleRegistry.register(new TopNav(style), "h", "Horizontal");

		// Define layouts
		SimplePageLayout oneColumn = new SimplePageLayout("oneCol",
				style.oneCol());
		layoutManager.add(oneColumn);

		SimplePageLayout twoCols = new SimplePageLayout("twoCols",
				style.twoCols());
		layoutManager.add(twoCols);

		SimplePageLayout threeCols = new SimplePageLayout("threeColsFixed",
				style.threeColsFixed());
		layoutManager.add(threeCols);

	}

	@Override
	public void start(HasWidgets.ForIsWidget container, StartupChain chain)
	{
		StaticActivityPanel header = staticActivityPanelProvider.get();
		StyleResource style = shellResources.style();
		header.setStyleName(style.pageHeader());
		header.start("header");
		// Wrap the haeder
		SimplePanel headerWrap = new SimplePanel();
		headerWrap.setStyleName(style.headerWrap());
		headerWrap.setWidget(header);
		container.add(headerWrap);

		FlowPanel activityWrap = new FlowPanel();
		activityWrap.setStyleName(style.activityWrap());
		container.add(activityWrap);

		ActivityPanel activityPanel1 = activityPanelProvider.get();
		activityPanel1.setId("act1");
		activityPanel1.setStyleName(style.activityPanel1());
		activityWrap.add(activityPanel1);

		ActivityPanel activityPanel2 = activityPanelProvider.get();
		activityPanel2.setId("act2");
		activityPanel2.setStyleName(style.activityPanel2());
		activityWrap.add(activityPanel2);

		ActivityPanel activityPanel3 = activityPanelProvider.get();
		activityPanel3.setId("act3");
		activityPanel3.setStyleName(style.activityPanel3());
		activityWrap.add(activityPanel3);

		StaticActivityPanel footer = staticActivityPanelProvider.get();
		footer.setStyleName(style.footerView());
		footer.start("footer");
		activityWrap.add(footer);

	}

}
